package top.mydb.hejianwei.dm;

import top.mydb.hejianwei.dm.pageCache.PageCache;
import top.mydb.hejianwei.tm.TransactionManager;

/**
 * DataManager 对上层提供接口
 */
public interface DataManager {
    DataItem read(long uid) throws Exception;
    long insert(long xid, byte[] data) throws Exception;
    void close();

    /**
     * 静态工厂方法，创建 DataManager
     */
    public static DataManager create(String path, long mem, TransactionManager tm) {
        PageCache pc = PageCache.create(path, mem);
        return new DataManagerImpl(pc, tm);
    }

    /**
     * 静态工厂方法，打开已有的 DataManager
     */
    public static DataManager open(String path, long mem, TransactionManager tm) {
        PageCache pc = PageCache.open(path, mem);
        return new DataManagerImpl(pc, tm);
    }
}